package com.gx.components
{

	import com.gx.interfaces.IBitmapObject;
	import com.gx.interfaces.IDrawable;
	import com.gx.interfaces.ISceneObject;
	
	import flash.display.Bitmap;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	

	public class TileMap extends SceneObject implements ISceneObject, IBitmapObject, IDrawable
	{
		public var tileWidth:int = 0;
		public var tileHeight:int = 0;
		public var rows:int = 0;
		public var columns:int = 0;
		public var tiles:Array = new Array();
		
		public function TileMap()
		{
		}
		
		public function render(layer:Bitmap):void
		{
			for(var yC:int = 0;yC < tiles.length; yC++)
			{
				var row:Array = tiles[yC] as Array;
				for(var xR:int = 0;xR < row.length;xR++)
				{
					var tileCoord:Point = row[xR] as Point;
					var tileSource:Rectangle = new Rectangle(tileCoord.x*tileWidth, tileCoord.y*tileHeight, tileWidth, tileHeight);
					var tilePosition:Point =  new Point((xR*tileWidth)+this.position.x,(yC*tileHeight)+this.position.y);
					layer.bitmapData.copyPixels(_bitmap.bitmapData, tileSource, tilePosition, null, null, true);
				}
			}
			
			
		}
		
		private var _clip:Rectangle;
		public function get clip():Rectangle{return _clip;}
		public function set clip(value:Rectangle):void{_clip = value;}
		
		
		private var _bitmap:Bitmap = new Bitmap();
		public function get bitmap():Bitmap
		{
			return _bitmap;
		}
		
		public function set bitmap(value:Bitmap):void
		{
			_bitmap = value;
		}
		
		
	}
}